package com.polaris.live.dialog.common

import android.content.Context
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.DialogCommonSureBinding

/**
 * CommonSureDialog    通用弹窗
 *
 * @author Created by 半仙 on 2023/11/1/001 18:57
 */
class CommonSureDialog(
    context: Context,
    private val title: String,
    private val confirmText: String? = null,
    private val onConfirmClickListener: ((backLive: Boolean) -> Unit)? = null,
) : CenterPopupView(context) {

    private lateinit var mBinding: DialogCommonSureBinding

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_common_sure
    }

    private var isBackLive = false

    override fun onCreate() {
        super.onCreate()
        mBinding = DialogCommonSureBinding.bind(popupImplView)
        mBinding.tvTitle.text = title
        if (confirmText != null) {
            mBinding.tvConfirm.text = confirmText
        }

        mBinding.tvConfirm.setOnSingleClickListener {
            isBackLive = true
            dismiss()
        }
    }

    override fun onDismiss() {
        onConfirmClickListener?.invoke(isBackLive)
        super.onDismiss()
    }
}